package com.project.controller;

import com.project.bean.UserBean;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.time.LocalDate;

@Controller
@RequestMapping("user")
public class UserController {

    @RequestMapping("find")
    @ResponseBody
    public String find(){
        return "/room/test.html";
    }

    @RequestMapping("getUser")
    @ResponseBody
    public UserBean getUser(){
        return new UserBean(2,"李四","123",8000,"13293029384", LocalDate.parse("2000-02-03"));
    }

    @RequestMapping("login")
    @ResponseBody
    public String login(String userName, String pwd,
                        String userCode, HttpServletRequest req){
        //从session中，取出系统产生的验证码
        String code = (String)req.getSession().getAttribute("code");
        //将系统产生的验证码和用户填写的验证码进行比对
        if(code.equalsIgnoreCase(userCode) == false){
            return "验证码错误";
        }

        if("java".equals(userName) && "123".equals(pwd)){
            return "登陆成功";
        }
        else{
            return "登陆失败";
        }
    }
}
